package com.jprocms.module.cms.convert.model;

import cn.hutool.json.JSONUtil;
import com.jpro.framework.common.pojo.PageResult;
import com.jprocms.module.cms.controller.admin.model.vo.*;
import com.jprocms.module.cms.dal.dataobject.model.ModelDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 模型 Convert
 *
 * @author jprocms
 */
@Mapper
public interface ModelConvert {

    ModelConvert INSTANCE = Mappers.getMapper(ModelConvert.class);

    ModelDO convert(ModelCreateReqVO bean);

    ModelDO convert(ModelUpdateReqVO bean);

    default ModelDO convert(ModelUpdateFieldReqVO bean) {
        if (bean == null) {
            return null;
        }
        ModelDO.ModelDOBuilder modelDO = ModelDO.builder();
        modelDO.id(bean.getId());
        modelDO.mainFields(bean.getMainFields());
        modelDO.customs(JSONUtil.toJsonStr(bean.getCustoms()));
        modelDO.rightFields(JSONUtil.toJsonStr(bean.getRightFields()));
        return modelDO.build();
    }

    ModelRespVO convert(ModelDO bean);

    List<ModelRespVO> convertList(List<ModelDO> list);

    PageResult<ModelRespVO> convertPage(PageResult<ModelDO> page);

    List<ModelExcelVO> convertList02(List<ModelDO> list);

}
